const path = require('path')
const CopyWebpackPlugin = require('copy-webpack-plugin')

module.exports = {
  publicPath: './',
  productionSourceMap: false,
  outputDir: 'dist/web',

  // 多页配置
  pages: {
    // 开发默认使用页面-方便开发
    index: {
      entry: './src/yun/main.js',
      template: './public/index.html',
      filename: 'index.html'
    },
    yun: {
      entry: './src/yun/main.js',
      template: './public/index.html',
      filename: 'yun.html'
    },
    // 正式环境页面
    shui: {
      entry: './src/shui/main.js',
      template: './public/index.html',
      filename: 'shui.html'
    }
  },

  configureWebpack: config => {
    if (process.env.MP_ENV === 'miniprogram') {
      config.plugins.push(new CopyWebpackPlugin([
        {
          from: path.resolve(__dirname, './cloudfunctions'),
          to: path.resolve(__dirname, './dist/mp/cloudfunctions'),
          toType: 'dir'
        },
        {
          from: path.resolve(__dirname, './project.config.json'),
          to: path.resolve(__dirname, './dist/mp/project.config.json'),
          toType: 'file'
        }
      ]))
    }
  },
}
